<?php 
include ("jpgraph-2.1.2/src/jpgraph.php"); 
include ("jpgraph-2.1.2/src/jpgraph_line.php"); 
include ("jpgraph-2.1.2/src/jpgraph_bar.php"); 
include '../includes/cDatabase.php';
include '../includes/variables.php';

$cDatabase = new database();

$connect = $cDatabase->connectToDatabase();
$activeDatabase = $cDatabase->getActiveDatabase($connect);
	
$db = $cDatabase->selectDatabase($connect, $activeDatabase);
$selectArray[0] = '*';
$result = $cDatabase->selectFromDatabase($connect, 'playerlist', $selectArray, "playerCode", $playerCode, NULL, NULL);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);

$maxWeeks = $cDatabase->GetMaxWeeks($connect);

for ($week = 1; $week <= $maxWeeks; $week++)
{
	if ($week < 10)
		$weekString = "week0".$week;
	else
		$weekString = "week".$week;
	$weekScore[$week-1] = $row[$weekString];
	//if ($accumWeekScore[$week-2] != NULL)
		$accumWeekScore[$week-1] = $accumWeekScore[$week-2] + $weekScore[$week-1];
}
	
 
$targ = array("#1","#2","#3","#4","#5","#6","#7","#8","#9","#10");
$alt = array(1,2,3,4,5,6,7,8,9,10); 

// Create the graph. 
$graph = new Graph(500,300,"auto");     
$graph->SetScale("textlin"); 
$graph->img->SetMargin(40,20,30,40); 
$graph->title->Set("Player Points Per Week"); 
$graph->title->SetFont(FF_FONT1,FS_BOLD);

// Setup axis titles
$graph->xaxis->title->Set("Week"); 
$graph->yaxis->title->Set("Points"); 

// Create the linear plot 
//$lineplot=new LinePlot($accumWeekScore); 
//$lineplot->mark->SetType(MARK_FILLEDCIRCLE);
//$lineplot->mark->SetWidth(2);
//$lineplot->mark->SetColor('black');
//$lineplot->mark->SetFillColor('red');
//$lineplot->SetCSIMTargets($targ,$alt);

// Create line plot
$barplot=new barPlot($weekScore);
$barplot->SetFillColor('#3333CC');
$barplot->SetWidth(1.0);
$barplot->SetCSIMTargets($targ,$alt);

// Add the plots to the graph 
//$graph->Add($lineplot); 
$graph->Add($barplot); 

$graph->Stroke();

?> 

